<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!--返回错误信息-->
<?php echo validation_errors(); ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <?php
    $title = [
        'title' => '新增商品',
    ];
    $this->load->view('/admin/common/header', $title);
    ?>
</head>

<body data-type="widgets">
<script src="/assets/js/theme.js"></script>
<div class="am-g tpl-g">

    <!--    头部   侧边菜单-->
    <?php $this->load->view('/admin/common/bodyLeft'); ?>
    <script type="text/javascript">
    	$(".js-sidebar-nav>li:nth-child(8)>ul").show(80);
    	$(".js-sidebar-nav>li:nth-child(8)>a>span").addClass("sidebar-nav-sub-ico-rotate");
    	$(".js-sidebar-nav>li:nth-child(8)>ul>li:nth-child(1)>a").addClass("active");
    </script>
    <!-- 内容区域 -->
    <div class="tpl-content-wrapper goods">
        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title  am-cf">
                                <ol class="am-breadcrumb am-breadcrumb-slash">
                                    <li><a href="/admin/goods/index?page=1">商品管理</a></li>
                                    <li class="am-active">新增商品</li>
                                </ol>
                            </div>
                        </div>
                        <form  method="post" id="submitForm" enctype="multipart/form-data" class="am-form am-text-sm">

                            <div class="widget-body  am-fr">
                                <div class="tpl-table-black-operation am-form-group">
                                    <a href="javascript:void(0);" class="tpl-table-black-operation-del">
                                        基本信息
                                    </a>
                                </div>

                                <div class="am-g-fixed">
                                    <div class="am-u-sm-12">
                                            <div class="am-u-md-6">
                                                <div class="am-form-group am-u-md-12">
                                                        <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                               for="productNo">商品编号</label>
                                                        <div class="am-u-md-10">
                                                            <input type="text" id="productNo" name="productNo" value="<?php echo 'ist'.date('Ymd').rand(100,999)?>" readonly>
                                                        </div>
                                                        
                                                </div>

                                                <div class="am-form-group am-u-md-12">
                                                        <label class="am-u-md-2 am-md-text-right am-padding-left-0 must">商品分类</label>
                                                        <div class="am-u-md-10" style="">
                                                            <select name="oneCategory" class="unlock" id="firstClassify" data-am-selected="{btnWidth: '32%'}">
                                                                <option value=""></option>
                                                                <option value="2">物料包</option>
                                                                <option value="3">书籍</option>
                                                                <option value="4">机器耗材</option>
                                                                <option value="8">供应商商品</option>
                                                                <option value="9">打印机租赁</option>
                                                            </select>
                                                            
                                                            <select name="twoCategory"  id="secondClassify" data-am-selected="{btnWidth: '32%'}">
                                                                <option value=""></option>
                                                            </select>
                                                            <select name="threeCategory"  id="thirdClassify" data-am-selected="{btnWidth: '32%'}">
                                                                <option value=""></option>
                                                            </select>
                                                        </div>
                                                </div>

                                                <div class="am-form-group am-u-md-12">
                                                        <label class="am-u-md-2 am-md-text-right am-padding-left-0"
                                                               for="isCanSize">是否启用规格</label>
                                                        <div class="am-checkbox am-u-md-10" style="padding-left: 30px">
                                                            <label><input name="isCanSize" type="checkbox" id="isCanSize">启用规格</label>
                                                        </div>
                                                </div>

                                                <div class="am-form-group price-box am-u-md-12">
                                                    <label class="am-u-md-2 am-md-text-right am-padding-left-0" for="price">商品价格</label>
                                                    <div class="am-u-md-10">
                                                        <input type="text" name="price" value="" id="price">
                                                    </div>

                                                        
                                                </div>
                                            </div>

                                            <div class="am-u-md-6">

                                                <div class="am-form-group am-u-md-12">
                                                    <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                           for="name">商品名称</label>
                                                    <div class="am-u-md-10">
                                                        <input type="text" name="name" value=""
                                                               id="name">
                                                    </div>

                                                        
                                                </div> 

                                                <div class="am-form-group am-u-md-12">
                                                        <label class="am-u-md-2 am-md-text-right am-padding-left-0"
                                                               for="goodsUnit">商品单位</label>
                                                        <div class="am-u-md-10">
                                                            <input type="text" name="goodsUnit" value=""
                                                               id="goodsUnit">
                                                        </div>

                                                        
                                                </div>

                                                <div class="am-form-group am-u-md-12">
                                                        <label class="am-u-md-2 am-md-text-right am-padding-left-0"
                                                               for="jbarcode">商品条形码</label>
                                                        <div class="am-u-md-10">
                                                            <input type="text" name="jbarcode" value=""
                                                               id="jbarcode">
                                                        </div>
                                                </div>


                                                <div class="am-form-group am-u-sm-12">
                                                    <label class="am-u-md-2 am-md-text-right am-padding-left-0 must"
                                                           for="supplier">供应商</label>
                                                    <div class="am-u-md-10">
                                                        <!-- <input type="text"  name="supplier" value=""
                                                           id="supplier"> -->
                                                        <select class="form-control" name="supplier" id="supplier" data-am-selected="{btnWidth: '100%',maxHeight: 200}">
                                                            <option value=""></option>

                                                            <?php
                                                            foreach ($supplier as $v2){
                                                                echo '<option value="'.$v2['name'].'">'.$v2['name'].'</option>';
                                                            }
                                                            ?>
                                                        </select>
                                                    </div>


                                                </div>


                                                <br />
                                            </div>
                                        </div>
                                </div>
                                <div class="am-u-sm-12 am-g-fixed specification" style="display: none;max-height: 800px;overflow: auto;">
                                    <div class="am-u-sm-12 specification-box" >
                                        <div class="tpl-table-black-operation am-form-group">
                                            <a href="javascript:void(0);" class="tpl-table-black-operation-del">
                                                商品规格
                                            </a>
                                        </div>
                                        <div style="margin-top: 20px;">
                                            <div class="am-u-sm-12 add_specification_box">
                                                
                                            </div>
                                            <div class="am-form-group am-u-sm-12 add_specification_btn">
                                                <button type="button" class="am-btn am-btn-primary add_specification" data-am-modal="{target: '#doc-modal-1'}">添加规格</button>
                                            </div>
                                        </div>
                                        <div class="am-u-sm-12" style="">
                                        	<table class="am-table am-table-bordered am-table-radius am-table-striped">
                                        		<thead class="specification-group-thead">
                                        			<tr>
                                                        <th style="width: 15%;"><input type="checkbox" name="check-all" class="check-all">全选</th>
                                                        <th style="width: 30%;">商品子编号</th>
                                                        <th style="width: 30%;">规格值组合</th>
                                                        <th style="width: 25px;">价格</th>
                                        			</tr>
    											</thead>
    											<tbody class="specification-group-tbody">
    												
    											</tbody>
                                        	</table>
                                        </div>
                                        <div class=" am-u-sm-4 col-end">
                                            <div class="am-u-sm-6">
                                                <input type="text" class="group-price-all" name="group-price-all">
                                            </div>
                                            <button class="am-btn am-btn-secondary group-price-all-btn am-u-sm-6">批量设置价格</button>
                                        </div>
                                    </div>
								</div>
                                
                                <div class="am-u-sm-12">
                                    <div class="tpl-table-black-operation am-form-group" >
                                        <hr />
                                        <a href="javascript:void(0);" class="tpl-table-black-operation-del">
                                            详细信息
                                        </a>
                                    </div>
                                    <div class="img-box">
                                        <span>商品主图:</span>
                                        <div class="am-inline-block am-form-file" style="top: 48%;left: -4%;">
                                          <button type="button" class="am-btn am-btn-default am-btn-sm">
                                          <i class="am-icon-cloud-upload"></i> 选择要上传的文件</button>
                                            <input type="file" id="image1" name="image1">
                                        </div>
                                        <!-- <input type="file" name="image1" id="image1"> -->
                                        <img src="" onerror="this.onerror=null;this.src='/assets/img/default.jpg'" class="seeimg1" alt="商品主图">
                                    </div>
                                    <div class="img-box">
                                        <span>商品副图1:</span>
                                        <div class="am-inline-block am-form-file" style="top: 48%;left: -4%;">
                                          <button type="button" class="am-btn am-btn-default am-btn-sm">
                                          <i class="am-icon-cloud-upload"></i> 选择要上传的文件</button>
                                            <input type="file" id="image2" name="image2">
                                        </div>
                                        <!-- <input type="file" name="image2" id="image2"> -->
                                        <img src="" class="seeimg2" onerror="this.onerror=null;this.src='/assets/img/default.jpg'" alt="商品副图1">
                                    </div>  
                                    <div class="img-box">
                                        <span>商品副图2:</span>
                                        <div class="am-inline-block am-form-file" style="top: 48%;left: -4%;">
                                          <button type="button" class="am-btn am-btn-default am-btn-sm">
                                          <i class="am-icon-cloud-upload"></i> 选择要上传的文件</button>
                                            <input type="file" id="image3"  name="image3">
                                        </div>
                                        <!-- <input type="file" name="image3" id="image3"> -->
                                        <img src="" class="seeimg3" onerror="this.onerror=null;this.src='/assets/img/default.jpg'"  alt="商品副图2">
                                    </div>
                                    <div class="img-box">
                                        <span>商品副图3:</span>
                                        <div class="am-inline-block am-form-file" style="top: 48%;left: -4%;">
                                          <button type="button" class="am-btn am-btn-default am-btn-sm">
                                          <i class="am-icon-cloud-upload"></i> 选择要上传的文件</button>
                                            <input type="file" id="image4" name="image4">
                                        </div>
                                        <!-- <input type="file" name="image4" id="image4"> -->
                                        <img src="" class="seeimg4" onerror="this.onerror=null;this.src='/assets/img/default.jpg'" alt="商品副图3">

                                    </div>
                                </div>



                                <div class="am-u-sm-12">
                                    <div class="tpl-table-black-operation am-form-group">
                                    <hr />
                                        <a href="javascript:void(0);" class="tpl-table-black-operation-del">
                                            审批信息
                                        </a>
                                    </div>
                                    <div class="am-g am-g-fixed">
                                        <div class="am-u-sm-12 am-form-group">
                                            <label class="am-u-md-1 am-md-text-right am-padding-left-0"
                                                   for="canshu">商品参数</label>
                                            <div class="am-u-md-11">
                                                <script id="canshu" name="canshu" type="text/plain" style="width: 100%; height: 200px;"></script>
                                            </div>
                                            
                                        </div>

                                        <div class="am-u-sm-12 am-form-group">
                                            <label class="am-u-md-1 am-md-text-right am-padding-left-0"
                                                   for="detail">商品详情</label>
                                           <!--  <textarea class="am-u-md-10 form-control" rows="5" id="detail" name="detail" style="border-radius: 3px;width:83%"></textarea> -->
                                           <div class="am-u-md-11">
                                                <script id="detail" name="detail" type="text/plain" style="width: 100%;height: 200px;"></script>
                                           </div>
                                        </div>

                                    </div>
                                </div>

                                <div class="am-u-sm-12 btn-box ">
                                    <button name="action" id="commit" class="am-btn am-btn-primary  tpl-btn-bg-color-success " style="width:220px;margin: 20px;">提交</button>

                                    <button onclick="back()" type="button" class="am-btn am-btn-primary tpl-btn-bg-color-success " style="width:220px">取消</button>

                                </div>

                              </div>


                        </form>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
</div>
<!--添加规格模态框-->
<div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-1">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">添加规格
            <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
        </div>
        <div class="am-modal-bd">
            <div class="am-form-group am-u-sm-12">
                <input type="text" class="" id="specificationName" placeholder="规格" style="width: 250px;height: 34px;padding: 0 10px;    margin-top: 14px;">
            </div>
            <button type="button" class="am-btn am-btn-primary add_specification_confirm">确定</button>
            <button type="button" class="am-btn am-btn-danger" data-am-modal-close>关闭</button>
        </div>
    </div>
</div>

<!--添加规格值模态框-->
<div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-2">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">添加规格值
            <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
        </div>
        <div class="am-modal-bd">
            <div class="specification_confirm_box" >
                <div class="am-form-group am-u-sm-12">
                    <input type="text" class="" id="specificationValue" placeholder="规格值" style="width: 250px;height: 34px;padding: 0 10px;margin-top: 14px;">
                </div>
                <button type="button" class="am-btn am-btn-primary add_specificationValue_confirm">确定</button>
                <button type="button" class="am-btn am-btn-danger " data-am-modal-close>关闭</button>
            </div>
        </div>
    </div>
</div>


<script src="/assets/js/amazeui.min.js"></script>
<script src="/assets/js/amazeui.datatables.min.js"></script>
<script src="/assets/js/dataTables.responsive.min.js"></script>
<script src="/assets/js/app.js"></script>
<script src="/assets/js/UEditor/ueditor.config.js"></script>
<script src="/assets/js/UEditor/ueditor.all.min.js"> </script>
<script src="/assets/js/zdy_form.js"></script>

<script>
	
    $(function(){

        var ueCanshu = UE.getEditor('canshu',{
            autoHeightEnabled: false,
        });
        var ueDetail = UE.getEditor('detail',{
            autoHeightEnabled: false,
        });

        imgChange("#image1",".seeimg1");
        imgChange("#image2",".seeimg2");
        imgChange("#image3",".seeimg3");
        imgChange("#image4",".seeimg4");

        //商品分类  级联菜单
        selectChange("#firstClassify","#secondClassify","/api/goods/twoCategory","one");
        selectChange("#secondClassify","#thirdClassify","/api/goods/threeCategory","two");

       
        var lockSubmit = false;

        $("#commit").bind("click",function(e){
    		e.preventDefault();

            if(lockSubmit){
                return false;
            }
            lockSubmit =true;
    		// 表单验证
    		var valid = zdy.validate.valid({
    			rules:{
    				productNo:{required:true},
    				name:{required:true},
    				firstClassify:{required:true}
    			}, message:{
    				productNo:{required:"商品编号不能为空"},
    				name:{required:"请填写商品名称"},
    				firstClassify:{required:"请选择商品分类"}
    			}	
    		});
    		if (!valid) {
                lockSubmit = false;
    			return;
    		}

            var formData = new FormData($('#submitForm')[0]);

            var canshuValue = ueCanshu.getContent();
            var detailValue = ueDetail.getContent();
            formData.append("canshu",canshuValue);
            formData.append("detail",detailValue);
            formData.append("specificationJson",getProductSpecification());
            formData.append("priceAndStockJson",getSpecificationGroup());

            if($('#isCanSize').prop("checked")){
                formData.append("isCanSize",1);
            }else{
                formData.append("isCanSize",0);
            }

            $.ajax({
                type: "POST",
                url : '/admin/goods/add',
//                url : '/api/test/a',
                data: formData,
//                dataType: "json",
                cache: false,  
                processData: false,  
                contentType: false,
                success: function(data){
                    if(data){
                        window.location.href = '/admin/goods/index?page=1';
                    }
                },
//                error: function(XMLHttpRequest, textStatus, errorThrown) {
//                     alert(XMLHttpRequest.status);
//                     alert(XMLHttpRequest.readyState);
//                     alert(textStatus);
//                       },
            });
        });
       
        //启用规格选中，显示输入规格框
        $('#isCanSize').change(function(){
            if($(this).prop("checked")){
                $('.specification').show();
                $(".price-box").hide();
            }else{
                $('.specification').hide();
                $(".price-box").show();

            }
        });
        
        //添加规格
        var specificationName_len = null;
        $(".add_specification_confirm").click(function(){
        	
            var specificationName = $("#specificationName").val();
            if(specificationName.replace(/(^\s*)|(\s*$)/g, "")==""){
                alert("请正确输入规格，不能为空。");
                $("#doc-modal-1").modal('close');

            }else{
                var specificationBox = "";
                specificationBox += '<div class="specificationValue_box fl am-u-sm-12">'
                                        +'<p class="am-u-md-2 specificationName specification-name">'
                                            + specificationName + ':'
                                        + '</p>'
                                        + '<button type="button" class="am-btn am-btn-primary fl add_specificationValue" data-am-modal="{target: \'#doc-modal-2\'}">新增规格值</button>'
                                 + '</div>';

                $(".add_specification_box").append(specificationBox);

                $("#doc-modal-1").modal('close');
                
                specificationName_len = $(".add_specification_box").children("div.specificationValue_box").length; //有几个规格值规格值

                if(specificationName_len == 3){
		            $(".add_specification").css("display","none");
		        }
            };
        });

        $('#doc-modal-1').on('closed.modal.amui', function(){
            $("#specificationName").val("");
        });


//      添加规格值
        $(document).on( "click" , ".add_specificationValue" , function(){
            var specificationP = $(this).siblings(".specificationName");
            specificationP.addClass("activeP");
        });

        $(".add_specificationValue_confirm").on("click", function(){
            var specificationValue = $("#specificationValue").val();
            var specificationP = $(".add_specification_box").find(".activeP");
            if(specificationValue.replace(/(^\s*)|(\s*$)/g, "")==""){

                alert("请正确输入规格值，不能为空。");
                $("#doc-modal-2").modal('close');

            }else{
                var specificationValueSpan = "" ;
                specificationValueSpan += '<span class="specificationValue am-u-md-1" >'
                                            + specificationValue
                                            + '<a href="javascript:;" onclick="deleteSpecificationValue(this)" class="am-close am-close-alt am-icon-times delete-specificationValue"></a>'
                                        + '</span>';

                specificationP.after(specificationValueSpan);

                var specificationValue_len = specificationP.siblings("span").length;
                
                if(specificationValue_len == 5){
                    specificationP.siblings("button").css("display","none");
                }
                addSpecificationGroup();
            }

            $("#doc-modal-2").modal('close');

        });

        //关闭规格值模态框
        $("#doc-modal-2").on('closed.modal.amui', function(){

            $(".add_specification_box").find(".activeP").removeClass("activeP"); 
            $("#specificationValue").val("");

        });

        //屏蔽回车键
        document.onkeydown = function () {
            if (window.event && window.event.keyCode == 13) {
                window.event.returnValue = false;
            }
        }

        //全选或全不选
        $(".check-all").click(function(){   
            if(this.checked){   
                $(".check-one").prop("checked", true);  
            }else{   
                $(".check-one").prop("checked", false);
            }   
        });

        //批量设置价格
        $(".group-price-all-btn").click(function(){
            var price = $(".group-price-all").val();
            if((!isNaN(price)) && (!price.replace(/(^\s*)|(\s*$)/g, "") == "")){
                $(".check-one:checked").each(function(){
                    var inputPrice = $(this).parent().siblings(".group-price-td").children(".group-price");
                    inputPrice.val(price);
                })
                $(".group-price-all").val("");
                return false;
            }else{
                alert("请输入正确价格！");
                return false;
            }
        });


        // var specificationTr = $(".specification-group-tbody").children("tr");
        // for(var i = 0;i < specificationTr; i++){
        //     var
        // }

        	
    })


        //商品分类  级联菜单
        function selectChange(changeId,nextSelect,url,changeNum){
            $(document).on("change" , changeId + ".unlock" , function(){

                var categoryValue = $(changeId).val();
                var data = changeNum + "Category=" + categoryValue;
                var option = "<option value=''><optian>";
                $.ajax({
                    type: "POST",
                    url : url,
                    data: data,
                    dataType: "json",
                    success: function(data){
                        for(var i = 0; i<data.length; i++){
                            if(data[i].product_categoryId){
                                option += '<option value="'+ data[i].product_categoryId +'">'+ data[i].name +'</option>';

                            }else{
                                option += '<option value="'+ data[i].id +'">'+ data[i].name +'</option>';
                            }
                        }
                        $(nextSelect).removeClass("unlock");
                        console.log($(nextSelect).hasClass("unlock"))
                        $(nextSelect).html(option);
                        setTimeout(function() {
                            $(nextSelect).addClass("unlock");
                        }, 0);

                        if(changeId == "#firstClassify" && $("#thirdClassify option").length != 1){
                            $("#thirdClassify").empty();
                        }
                        
                    },
                    error: function (data) {  
                        alert(XMLHttpRequest.status);
                        alert(XMLHttpRequest.readyState);
                        alert(textStatus);
                    }
                });
            });
        }


        //file上传 图片显示
        function imgChange(fileId,imgBoxClass){

            $(fileId).change(function(event) {
                var files = event.target.files, file;        
                if (files && files.length > 0) {
                  // 获取目前上传的文件
                  file = files[0];
                  if(file.size > 1024 * 1024 * 2) {
                    alert('图片大小不能超过 2MB!');
                    return false;
                  }
                  var URL = window.URL || window.webkitURL;
                  // 通过 file 生成目标 url
                  var imgURL = URL.createObjectURL(file);
                  // 用这个 URL 产生一个 <img> 将其显示出来
                  $(imgBoxClass).attr('src', imgURL);
                  // 使用下面这句可以在内存中释放对此 url 的伺服，跑了之后那个 URL 就无效了
                  // URL.revokeObjectURL(imgURL);
                }
            });
        }



    //获取商品规格
    function getProductSpecification(){
        var specifications = [];
        var specificationNames = $('.specification-name');
        var k = 0;
        for(var i = 0; i < specificationNames.length; i++){
            var specificationName = specificationNames.eq(i);
            var specificationValues = specificationName.nextAll(".specificationValue");
            var specificationGroup = [];
            for(var j = 0; j < specificationValues.length; j++){
                var specificationValue = specificationValues.eq(j);
                specificationGroup[j] =  specificationValue.text();
            }
            if(specificationGroup.length != 0){
                var specification = {};
                specification.name = specificationName.html();
                specification.value = specificationGroup;
                specifications[k] = specification;
                k++;
            }
        }
        var specificationJSON = JSON.stringify(specifications);

        return specificationJSON;
    }

    //获取规格组合
    function getSpecificationGroup(){
        var groups = [];
        var groupNoTds = $('.group-no');
        for(var i = 0;i < groupNoTds.length; i++){
            var groupNoTd = groupNoTds.eq(i);
            var group = {};
            group.groupNo = groupNoTd.html();
            var groupValues = [];
            var groupValueTds = groupNoTd.nextAll('.group-value');
            for(var j = 0; j < groupValueTds.length; j++){
                var groupValueTd = groupValueTds.eq(j);
                groupValues[j] =  groupValueTd.html();
            }
            group.groupValue = groupValues;
            var groupPriceTds = groupNoTd.nextAll('.group-price-td');
            var groupPriceInputs = groupPriceTds.eq(0).find('.group-price');
            group.groupPrice = groupPriceInputs.eq(0).val();
            groups[i] = group;
        }
        var specificationGroupJSON = JSON.stringify(groups);
        return specificationGroupJSON;

    }
    //添加规格列表
    function addSpecificationGroup(){
        var specificationNames = $('.specificationName');
        var specificationGroups = [];
        var k = 0;
        for(var i = 0; i < specificationNames.length; i++){
            var specificationName = specificationNames.eq(i);
            var specificationValues = specificationName.nextAll(".specificationValue");
            var specificationGroup = [];
            for(var j = 0; j < specificationValues.length; j++){

                var specificationValue = specificationValues.eq(j);
                specificationGroup[j] =  specificationValue.text();
            }
            if(specificationGroup.length != 0){
                specificationGroups[k] = specificationGroup;
                k++;
            }
        }
        if(specificationGroups.length > 1){
            var groups = multiCartesian(specificationGroups);
        }else{
            var groups = [];
            var specificationGroup = specificationGroups[0];
            var specificationGroupLen = null;

            if(specificationGroup == undefined){
                specificationGroupLen = 0;
            }else{
                specificationGroupLen = specificationGroup.length;
            }

            for(var i = 0; i < specificationGroupLen; i++){
                var group = [];
                group[0] = specificationGroup[i];
                groups[i] =  group;
            }
        }

        $('.specification-group-tbody').empty();
        for(var i=0;i<groups.length;i++){
            var groupNo = new Date().getTime();
            var rand = "";
            for(var n = 0; n < 3; n++){
                var r = Math.floor(Math.random() * 10);
                rand += r;
            }
            var tr = '<tr><td><input type="checkbox" name="checkbox" class="check-one"></td><td class="group-no">'+groupNo+rand+'</td>';
            var group = groups[i];
            var value = [];
            for(var j = 0 ;j < group.length; j++){
                var a = group[j];
                value += a+",";
            }
            value = value.slice(0,value.length-1);
            tr += '<td class="group-value">'+value+'</td>';
            tr += '<td class="group-price-td"><input type="text" class="group-price"></td></tr>';
            $('.specification-group-tbody').append(tr);
        }
    }

    // 删除
    function deleteSpecificationValue(even){

        var specificationValueLen = $(even).parents(".specificationValue_box").children("span").length - 1; //这里还没有删除span所以要减一
        var btn = $(even).parents(".specificationValue_box").children("button");
  
        $(even).parent().remove();
        $('.specification-group-tbody').empty();
        addSpecificationGroup();
        
        if(specificationValueLen < 5) {
            btn.css("display","block");
        }

    }

    //笛卡尔积  
    var Cartesian = function(a, b) {
        var ret = [];
        for(var i = 0; i < a.length; i++) {
            for(var j = 0; j < b.length; j++) {
                ret.push(ft(a[i], b[j]));
            }
        }
        return ret;
    }
    var ft = function(a, b) {
        if(!(a instanceof Array))
            a = [a];
        var ret = Array.call(null, a);
        ret.push(b);
        return ret;
    }
    //多个一起做笛卡尔积  
    var multiCartesian = function(data) {
        var len = data.length;
        if(len == 0)
            return [];
        else if(len == 1)
            return data[0];
        else {
            var r = data[0];
            for(var i = 1; i < len; i++) {
                r = Cartesian(r, data[i]);
            }
            return r;

        }
    }
    
</script>
<script>
    function back() {
        window.history.back();
    }
</script>
</body>

</html>